package com.duobeiyun.gmstest.work

import android.content.Context
import android.util.Log
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
import com.duobeiyun.generamessagesdk.ErrorInfo
import com.duobeiyun.generamessagesdk.ResultCallback
import com.duobeiyun.gmstest.TestInstance
import com.duobeiyun.gmstest.log.LogDebug
import com.duobeiyun.gmstest.log.LogOuter
import com.duobeiyun.gmstest.work.sample.WorkAsyncMode
import kotlinx.coroutines.CancellableContinuation
import kotlinx.coroutines.suspendCancellableCoroutine
import java.util.*
import kotlin.coroutines.resume

/**
 * 测试订阅用户在线状态
 */
class WorkPeerOnLineStatus(appContext: Context, workerParams: WorkerParameters) :
        WorkAsyncMode(appContext, workerParams) {

    override fun setNumber() {
        TAG = "WorkPeerOnLineStatus"
        number = "2"
    }
    override fun realWork(continuation: CancellableContinuation<Result>) {

        TestInstance.subscribePeersOnlineStatus(TestInstance.onLineSet, object : ResultCallback<Void> {
            override fun onFailure(errorInfo: ErrorInfo) {
                LogDebug.logE(errorInfo.toString())
                LogOuter.print("number:$number \t result:${false} \t name:PeerOnLineStatus ")
                Log.d(TAG, "onFailure ListenableWorker: $errorInfo")

            }

            override fun onSuccess(responseInfo: Void?) {
                LogOuter.print("number:$number \t result:${true} \t name:PeerOnLineStatus ")
                Log.d(TAG, "doWork ListenableWorker: finish")
            }
        })
        continuation.resume(Result.success())
    }


}